{  12 March 2011. Individual Olympiad. Problem set: http://neerc.ifmo.ru/school/io/archive/20110312/problems-20110312-individual.pdf
	Problem B
	Points: 100
}
var n,m,k,i,j,g,r1,r2:longint; min,max,r:int64;
begin
assign(input,'game.in');
assign(output,'game.out');
reset(input);
rewrite(output);
read(n,m,k,r);
min:=r;
max:=r;
r1:=-1;
r2:=-1;
for g:=1 to n do begin
    read(j,i);
    if (i=1) and (j=1) then begin
       inc(max,k);
       dec(min,k);
    end else
    if i=1 then begin
       inc(max);
       inc(min);
    end else
    if j=1 then begin
       dec(max);
       dec(min);
    end;
    if (max>m) and (r1=-1) then r1:=g;
    if (min<-m) and (r2=-1) then r2:=g;
end;
write(r1,' ',r2);
close(input);
close(output);
end.